package com.ckd.flyingtrip.adapter;

import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.ckd.flyingtrip.R;
import com.ckd.flyingtrip.activity.BaseActivity;
import com.ckd.flyingtrip.javabean.DingdanBean;
import com.ckd.flyingtrip.utils.Tools;

import java.util.List;

public class MyDingdanAdapter extends BaseAdapter {

    private BaseActivity context;
    private List<DingdanBean> list;
    public MyDingdanAdapter(BaseActivity context, List<DingdanBean> list){
        this.context = context;
        this.list = list;
    }
    @Override
    public int getCount() {
        if (Tools.isEmpeyNull(list)) {
            return list.size();
        }
        return 0;
    }

    @Override
    public Object getItem(int i) {
        return list.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup viewGroup) {
        final ViewHolder holder;
        View view = null;
        if (convertView == null) {
            view = View.inflate(context, R.layout.item_dingdan, null);
            holder = new ViewHolder();
            view.setTag(holder);

            holder.txt_dp_name = view.findViewById(R.id.txt_dp_name);
            holder.txt_ddc_name = view.findViewById(R.id.txt_ddc_name);
            holder.txt_city = view.findViewById(R.id.txt_city);
            holder.txt_time = view.findViewById(R.id.txt_time);
            holder.txt_bianhao = view.findViewById(R.id.txt_bianhao);
            holder.txt_money = view.findViewById(R.id.txt_money);
            holder.img = view.findViewById(R.id.img);
        } else {
            view = convertView;
            holder = (ViewHolder) convertView.getTag();
        }
        DingdanBean dingdanBean = list.get(position);
        Tools.loadImg(dingdanBean.getBicyclePictureUrl(),holder.img);
        holder.txt_ddc_name.setText(dingdanBean.getBicycleName());
        holder.txt_city.setText("取车地点:"+dingdanBean.getBicycleExtractAddress());
        holder.txt_time.setText("下单时间:"+dingdanBean.getOrderCreateTime());
        holder.txt_bianhao.setText("订单编号:"+dingdanBean.getOrderCreateTime());
        holder.txt_money.setText("共"+dingdanBean.getBicycleDepreciation()+"元");


        return view;
    }

    public static final class ViewHolder {
        private TextView txt_dp_name,txt_ddc_name,txt_city,txt_time,txt_bianhao,txt_money;
        private ImageView img;
    }
}